<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">
    </script>
</head>
<body>
    <div id="result"></div>
    <input type="file" id="file"/>
    <input type="button" name="上传" value="上传" onclick="uploadFile()"/>
<script>
    //Ajax 上传文件
    function uploadFile(){
        //这一步是我们要转换的javascript 对象，获取文件对象
        var file = $("#file")[0].files[0];
        var formData = new FormData();
        //要和参数名称一致
        formData.append("files",file)
        $.ajax({
            type: 'post',
            url: '/upload2',
            processData: false,//不需要处理数据
            contentType: false,//ajax 上传图片不需要设置contentType
            data: formData,
            success: function (msg){
                $("#result").html(msg);
            }
        })
    }

</script>
</body>
</html>